using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace BPMN.MainWindow
{
    public class PoolList : IEnumerable<Pool>
    {

        List<Pool> pools = new List<Pool>();

        public Pool this[int index]
        {
            get
            {
                if (index >= 0)
                {
                    return pools[index];
                }
                else
                {
                    return null;
                }
            }
            set
            {
                pools[index] = value;
            }
        }

        public Pool this[string name]
        {
            get
            {
                for (int i = 0; i < pools.Count; i++)
                {
                    if (pools[i].Name == name)
                    {
                        return pools[i];
                    }
                }
                return null;
            }
            set
            {
                for (int i = 0; i < pools.Count; i++)
                {
                    if (pools[i].Name == name)
                    {
                        pools[i] = value;
                    }
                }
            }
        }

        public int Count
        {
            get
            {
                return pools.Count;
            }
        }

        public void Add(Pool item)
        {
            pools.Add(item);
        }

        public void Clear()
        {
            pools.Clear();
        }

        public int GetIndex(string name)
        {
            for (int i = 0; i < pools.Count; i++)
            {
                if (pools[i].Name == name)
                {
                    return i;
                }
            }
            return -1;
        }

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return pools.GetEnumerator();
        }

        #endregion

        #region IEnumerable<Pool> Members

        public IEnumerator<Pool> GetEnumerator()
        {
            return pools.GetEnumerator();
        }

        #endregion
    }
    public class BPMNClass
    {
        #region Fields

        PoolList pools = new PoolList();
        SizeF size;
        int currentPoolIndex=-1;

        #endregion

        #region Properties

        public PoolList Pools
        {
            get
            {
                return pools;
            }
            set
            {
                pools = value;
            }
        }
        public SizeF Size
        {
            get
            {
                return size;
            }
            set
            {
                size = value;
            }
        }
        public int CurrentPoolIndex
        {
            get
            {
                return currentPoolIndex;
            }
            set
            {
                if (currentPoolIndex >= 0)
                {
                    CurrentPool.State = FigureState.Unselected;
                    foreach (Lane lane in CurrentPool.Lanes)
                    {
                        lane.State = FigureState.Unselected;
                    }
                    //CurrentPool.CurrentLaneIndex = -1;
                }
                currentPoolIndex = value;
                pools[currentPoolIndex].State = FigureState.Selected;
            }
        }
        public Pool CurrentPool
        {
            get
            {
                if (currentPoolIndex >= 0)
                {
                    return pools[currentPoolIndex];
                }
                return null;
            }
            set
            {
                pools[currentPoolIndex] = value;
            }
        }
        #endregion

        public BPMNClass(SizeF size)
        {
            this.size = size;
        }

    }
}
